package com.ship.contract.bean;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ship.common.core.base.ContractBaseBean;
import com.ship.common.core.base.Joinable;
import com.ship.common.core.enums.CurrencyStatus;
import com.ship.common.core.enums.OrderStatus;
import com.ship.common.core.enums.OrderType;
import com.ship.contract.utils.NumberFormatUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.math.BigDecimal;
import java.util.Date;

/**
 * 支付结算表
 */
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("pay_fund_management")
public class PayFundManagement extends ContractBaseBean implements Joinable {
    /**
     * 主键
     */
    @TableId
    @TableField("id")
    private Long id;

    /**
     * 公司名称
     */
    @TableField("company_name")
    private String companyName;

    /**
     * 公司类型
     */
    @TableField("company_type")
    private Integer companyType;

    /**
     * 关联合同id
     */
    @TableField("affiliated_contract_id")
    private Long affiliatedContractId;

    /**
     * 关联合同名称
     */
    @TableField("contract_name")
    private String contractName;

    /**
     * 账户余额
     */
    @TableField("account_balance")
    private BigDecimal accountBalance;

    /**
     * 最近一次支付时间
     */
    @TableField("last_payment_time")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date lastPaymentTime;

    /**
     * 订单编号
     */
    @TableField("pay_order_number")
    private String payOrderNumber;

    /**
     * 订单类型
     */
    @TableField("order_type")
    private Integer orderType;

    /**
     *订单类型字符串
     */
    @TableField(exist = false)
    private String orderTypeStr;

    /**
     * 订单类型字符串
     */
    @TableField(exist = false)
    private String orderTypeListForSearch;

    /**
     * 订单金额
     */
    @TableField("pay_amount")
    private BigDecimal payAmount;

    /**
     * 订单金额
     */
    @TableField(exist = false)
    private String payAmountStr;

    /**
     * 对方账户名称
     */
    @TableField("opposite_account_name")
    private String oppositeAccountName;

    /**
     * 对方银行地址
     */
    @TableField("opposite_bank_address")
    private String oppositeBankAddress;

    /**
     * 对方账户号码
     */
    @TableField("opposite_account_number")
    private String oppositeAccountNumber;

    /**
     * SWIFT Code/BIC
     */
    @TableField("swift_code")
    private String swiftCode;

    /**
     * 申请人
     */
    @TableField("applicant_people")
    private String applicantPeople;

    /**
     * 申请时间
     */
    @TableField("applicant_time")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date applicantTime;

    /**
     * 支付时间
     */
    @TableField("pay_time")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date payTime;

    /**
     * 支付状态
     */
    @TableField("pay_status")
    private Integer payStatus;

    /**
     * 航次号
     */
    @TableField("voyage_no")
    private String voyageNo;

    /**
     * 支付金额单位（1：美元、2：欧元、3：人民币）
     */
    @TableField("pay_amount_unit")
    private Integer payAmountUnit;
    /**
     * 截止支付时间
     */
    @TableField("pay_end_time")
    private Date payEndTime;
    /**
     * 经办人
     */
    @TableField("handle_people")
    private String handlePeople;

    /**
     * 审批人
     */
    @TableField("approved_people")
    private String approvedPeople;

    /**
     * 订单状态（1：未审核、2：已审核、3：已付款）
     */
    @TableField("order_status")
    private Integer orderStatus;

    /**
     *订单状态字符串
     */
    @TableField(exist = false)
    private String orderStatusStr;

    /**
     * 备注
     */
    @TableField("order_remark")
    private String orderRemark;
    /**
     * 订单id
     */
    @TableField("order_id")
    private Long orderId;

    @Override
    public String getLabel() {
        return null;
    }

    @Override
    public String getValue() {
        return null;
    }

    public String getPayAmountStr() {
        String result = null;
        if (getPayAmount() != null) {
            result = NumberFormatUtil.numericFormatting(payAmount) + getPayAmountUnitStr();
        }
        return result;
    }

    public String getPayAmountUnitStr() {
        String result = null;
        if (getPayAmountUnit() != null) {
            if (payAmountUnit.equals(CurrencyStatus.DOLLAR.getCode())) {
                result = CurrencyStatus.DOLLAR.getInfo();
            } else if (payAmountUnit.equals(CurrencyStatus.EURO.getCode())) {
                result = CurrencyStatus.EURO.getInfo();
            } else if (payAmountUnit.equals(CurrencyStatus.RMB.getCode())) {
                result = CurrencyStatus.RMB.getInfo();
            }
        }
        return result;
    }

    public String getOrderStatusStr(){
        String result = null;
        if (getOrderStatus()!=null) {
            if(orderStatus.equals(OrderStatus.UNAUDITE.getCode())){
                result = OrderStatus.UNAUDITE.getInfo();
            }else if(orderStatus.equals(OrderStatus.AUDITE.getCode())){
                result = OrderStatus.AUDITE.getInfo();
            }else if(orderStatus.equals(OrderStatus.PAID.getCode())){
                result = OrderStatus.PAID.getInfo();
            }
        }
        return result;
    }

    public String getOrderTypeStr(){
        String result = null;
        if (getOrderType()!=null) {
            if(orderType.equals(OrderType.LOADING_PORT_PAY.getCode())){
                result = OrderType.LOADING_PORT_PAY.getInfo();
            }else if(orderType.equals(OrderType.LOADING_PORT_PAY_END.getCode())){
                result = OrderType.LOADING_PORT_PAY_END.getInfo();
            }else if(orderType.equals(OrderType.UNLOADING_PORT_PAY.getCode())){
                result = OrderType.UNLOADING_PORT_PAY.getInfo();
            }else if(orderType.equals(OrderType.UNLOADING_PORT_PAY_END.getCode())){
                result = OrderType.UNLOADING_PORT_PAY_END.getInfo();
            }else if(orderType.equals(OrderType.CHARTERER_INSURANCE.getCode())){
                result = OrderType.CHARTERER_INSURANCE.getInfo();
            }else if(orderType.equals(OrderType.CARGO_INSURANCE.getCode())){
                result = OrderType.CARGO_INSURANCE.getInfo();
            }else if(orderType.equals(OrderType.LOADING_PORT_THIRD_PARTY.getCode())){
                result = OrderType.LOADING_PORT_THIRD_PARTY.getInfo();
            }else if(orderType.equals(OrderType.UNLOADING_PORT_THIRD_PARTY.getCode())){
                result = OrderType.UNLOADING_PORT_THIRD_PARTY.getInfo();
            }else if(orderType.equals(OrderType.SHIP_RENTAL.getCode())){
                result = OrderType.SHIP_RENTAL.getInfo();
            }else if(orderType.equals(OrderType.SHIP_NEXT_RENTAL.getCode())){
                result = OrderType.SHIP_NEXT_RENTAL.getInfo();
            }else if(orderType.equals(OrderType.SHIP_END_RENTAL.getCode())){
                result = OrderType.SHIP_END_RENTAL.getInfo();
            }else if(orderType.equals(OrderType.DELIVERY_FEE.getCode())){
                result = OrderType.DELIVERY_FEE.getInfo();
            }else if(orderType.equals(OrderType.RETURN_SHIP_FEE.getCode())){
                result = OrderType.RETURN_SHIP_FEE.getInfo();
            }else if(orderType.equals(OrderType.LNG_DELIVERY_FEE.getCode())){
                result = OrderType.LNG_DELIVERY_FEE.getInfo();
            }else if(orderType.equals(OrderType.LNG_RETURN_FEE.getCode())){
                result = OrderType.LNG_RETURN_FEE.getInfo();
            }else if(orderType.equals(OrderType.FUEL_DELIVERY_SETTLE.getCode())){
                result = OrderType.FUEL_DELIVERY_SETTLE.getInfo();
            }else if(orderType.equals(OrderType.FUEL_RETURN_SETTLE.getCode())){
                result = OrderType.FUEL_RETURN_SETTLE.getInfo();
            }
        }
        return result;
    }
}
